﻿using EdiNet;
using Xunit;
using System;
using System.IO;
using System.Text;
using System.Xml;

namespace EdiNet.Test
{

    public class EdiReaderWriterCrossTest
    {


        [Fact()]
        public void EdiReaderWriterTest()
        {
            string fn2 = Path.GetTempFileName();
            Stream ediStream = StreamHelper.GetResourceStream(EdiStreamReaderTest.ResourceBasePath, "CR.txt");
            Stream ediOutStream = File.Create(fn2);
            EdiStreamReader rd = new EdiStreamReader(ediStream);
            DataSegment seg = rd.ReadSegment();
            
            EdiStreamWriter wr = new EdiStreamWriter(ediOutStream, rd.CurrentEdiReaderWriterSettings);
            do
            {
                wr.WriteSegment(seg);
                seg = rd.ReadSegment();
            } while (null != seg);

            rd.Close();
            wr.Close();

            using (StreamReader s1 = new StreamReader(StreamHelper.GetResourceStream(EdiStreamReaderTest.ResourceBasePath, "CR.txt")), s2 = new StreamReader(fn2))
            {
                string content1 = s1.ReadToEnd();
                string content2 = s2.ReadToEnd();
                Assert.Equal(content1, content2);
            }
        }
    }
}
